package rsj.service.report;

import com.alibaba.fastjson.JSON;
import com.rlyy.aibase.utils.base.TableNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import rsj.api.report.entity.AccountProductReport;
import rsj.api.report.entity.AccountProductReportDetail;
import rsj.api.report.entity.ReportParam;
import rsj.sql.account.AccountProductReportDao;

import java.util.List;

/**
 * 账号接口报表
 *
 * @author yuanqinglong
 * @since 2021/7/22 9:09
 */
@Service
public class AccountProductReportServiceImpl implements IReportService<AccountProductReport, AccountProductReportDetail, ReportParam> {


    @Autowired
    private AccountProductReportDao accountProductReportDao;




    /**
     * 报告列表
     *
     * @param reportParam 报告参数
     * @return {@link List<AccountProductReport>}
     */
    @Override
    public List<AccountProductReport> reportList(ReportParam reportParam) {
        TableNode reportList = accountProductReportDao.accountProductReportList(reportParam);
        List<AccountProductReport> accountProductReports = JSON.parseArray(reportList.toJson(), AccountProductReport.class);
        accountProductReports.forEach(AccountProductReport::calculateRate);
        return accountProductReports;
    }

    /**
     * 报告数
     *
     * @param reportParam 报告参数
     * @return int
     */
    @Override
    public int reportCount(ReportParam reportParam) {
        return accountProductReportDao.accountProductReportCount(reportParam).valueInt();
    }

    /**
     * 详细的列表
     *
     * @param reportParam 报告参数
     * @return {@link List<AccountProductReportDetail>}
     */
    @Override
    public List<AccountProductReportDetail> detailList(ReportParam reportParam) {
        TableNode reportDetailList = accountProductReportDao.accountProductReportDetailList(reportParam);
        List<AccountProductReportDetail> accountProductReportDetails = JSON.parseArray(reportDetailList.toJson(), AccountProductReportDetail.class);
        accountProductReportDetails.forEach(AccountProductReportDetail::calculateRate);
        return accountProductReportDetails;
    }

    /**
     * 详细的计算
     *
     * @param reportParam 报告参数
     * @return int
     */
    @Override
    public int detailCount(ReportParam reportParam) {
        return accountProductReportDao.accountProductReportDetailCount(reportParam).valueInt();
    }



}
